import pygame
import sys
import logging
import event
from event_looper import EventLooper
from dispatcher import Dispatcher
from filter import *

SCREEN_RECT = pygame.rect.Rect(0,0,800, 600)
LOG_FILENAME = 'logs.txt'

def init():
    pygame.init()
    pygame.display.set_mode(SCREEN_RECT.size)
    
    logging.basicConfig(level = logging.WARNING,
                        filename = LOG_FILENAME)

def main():
    init()
    
    event_dispatcher = Dispatcher()
    
    quit_filter = QuitFilter()
    key_timestamp = TimeStampFilter()
    try:
        event_dispatcher.attach(event.QuitEvent.event_id, quit_filter)
        event_dispatcher.attach(event.KeyDownEvent.event_id, key_timestamp)
    except Exception,data:
        logging.critical("Can't attach filter!Error msg:%s." % data)
        sys.exit()
    
    event_looper = EventLooper(event_dispatcher)
    event_looper.start()
    
if __name__ == '__main__':
    main()